import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
	plugins: [
		vue(),
	],
	resolve: {
		alias: {
			'@': fileURLToPath(new URL('./src', import.meta.url))
		}
	},
	build: {
		rollupOptions: {
			// https://rollupjs.org/guide/en/#outputmanualchunks
			output: {
				manualChunks: {
					'group-index': [
						'@/views/index/frame.vue',
						'@/views/index/guide.vue',
						'@/views/user/login.vue',
						'@/views/user/register.vue',
					],
					'group-problem': [
						'@/views/problem/list.vue',
						'@/views/problem/detail.vue',
					],
					'group-status': [
						'@/views/status/list.vue',
						'@/views/status/detail.vue',
					],
					'group-rank': [
						'@/views/rank/list.vue',
					],
					'group-contest': [
						'@/views/Contest/frame.vue',
						'@/views/contest/list.vue',
						'@/views/contest/detail.vue',
						'@/views/contest/problem.vue',
						'@/views/contest/rank.vue',
						'@/views/contest/status.vue',
					],
					'group-group': [
						'@/views/group/frame.vue',
						'@/views/group/index.vue',
						'@/views/group/list.vue',
						'@/views/group/creation.vue',
						'@/views/group/joined.vue',
						
						'@/views/group/detail.vue',
						'@/views/group/join.vue',
						'@/views/group/members.vue',
						'@/views/group/notifications.vue',
						'@/views/group/tasks.vue',
					],
					'group-paste': [
						'@/views/paste/publish.vue',
						'@/views/paste/detail.vue',
					],
					'group-user': [
						'@/views/user/profile/detail.vue',
						'@/views/user/profile/modify.vue',
						'@/views/user/password/change.vue',
						'@/views/user/password/forgot.vue',
						'@/views/user/info.vue',
					]
				},
			},
		},
	},
	server: {
		// 配置代理
		proxy: {
			// 当请求路径以'/api'开头时，将会被代理到'http://localhost:3000'
			'/api': {
				// target: 'http://localhost:1122',
				target: 'http://toj.frp.xpman.top',
				changeOrigin: true, // 是否改变请求源头，开启后服务器会认为请求是从target地址发出的
				// rewrite: (path) => path.replace(/^\/api/, ''), // 重写请求路径，去除前缀
				rewrite: (path) => path.replace(/^\/api/, '/api/v1/'), // 重写请求路径，去除前缀
			},
			// 可以根据需要添加更多代理规则
			// '/otherApi': {
			//   target: 'http://another-backend.com',
			//   changeOrigin: true,
			//   rewrite: (path) => path.replace(/^\/otherApi/, ''),
			// },
		},
	},
})
